import request from '@/utils/request'

export function addTest(data) {
  return request({
    url: '/v1/test/add',
    method: 'post',
    data: {
      groupId: data.group,
      projectId: data.projectId,
      lv1ModuleId: data.moduleId[0],
      lv2ModuleId: data.moduleId[1],
      taskId: data.taskId,
      relateId: data.relateId,
      respPerson: data.respPerson,
      devPerson: data.devPerson,
      testPerson: data.testPerson,
      describe: data.describe,
      questionType: data.questionType,
      remark: data.remark,
      preRepair: data.preRepair,
      preOnline: data.preOnline,
      tempCode: data.upload.tempCode,
      attachments: data.uploadFileList,
      isBack: data.isBack,
      codeRepositoryName: data.codeRepository
    }
  })
}

export function editTest(data) {
  return request({
    url: '/v1/test/edit',
    method: 'put',
    data: {
      test_id: data.tId,
      groupId: data.group,
      projectId: data.projectId,
      lv1ModuleId: data.moduleId[0],
      lv2ModuleId: data.moduleId[1],
      taskId: data.taskId,
      relateId: data.relateId,
      respPerson: data.respPerson,
      devPerson: data.devPerson,
      testPerson: data.testPerson,
      describe: data.describe,
      questionType: data.questionType,
      remark: data.remark,
      preRepair: data.preRepair,
      preOnline: data.preOnline,
      tempCode: data.upload.tempCode,
      attachments: data.uploadFileList,
      codeRepositoryName: data.codeRepository
    }
  })
}

export function testSelf(data) {
  return request({
    url: '/v1/test/self',
    method: 'put',
    data: {
      tid: data.tid,
      tempCode: data.tempCode
    }
  })
}

export function testClose2(data) {
  return request({
    url: '/v1/test/close2',
    method: 'put',
    data: {
      tid: data.tid,
      tempCode: data.tempCode
    }
  })
}

export function findByPage(data, pageSize, pageNum) {
  return request({
    url: '/v1/test/findByPage',
    method: 'get',
    params: {
      groupId: data.group,
      projectId: data.projectId,
      devPerson: data.devPerson,
      testPerson: data.testPerson,
      lv2ModuleId: data.lv2ModuleId,
      status: data.status,
      noClose: data.noClose,
      noRefuse: data.noRefuse,
      type: data.type,
      pageSize: pageSize,
      pageNum: pageNum,
    }
  })
}

export function exportExcel(data) {
  return request({
    url: '/v1/test/export',
    method: 'post',
    data: {
      groupId: data.group,
      projectId: data.projectId,
      devPerson: data.devPerson,
      testPerson: data.testPerson,
      lv2ModuleId: data.lv2ModuleId,
      status: data.status,
      noClose: data.noClose,
      noRefuse: data.noRefuse,
      type: data.type,
    },
    responseType: 'blob'
  })
}

export function downLoad(fileName) {
  return request({
    url: '/file/' + fileName,
    method: 'get'
  })
}

export function remove(id) {
  return request({
    url: '/v1/task/remove/' + id,
    method: 'delete'
  })
}

export function testDispatch(id) {
  return request({
    url: '/v1/test/dispatch/' + id,
    method: 'put'
  })
}

export function taskTest(id) {
  return request({
    url: '/v1/task/test/' + id,
    method: 'put'
  })
}

export function testOpen(id) {
  return request({
    url: '/v1/test/open/' + id,
    method: 'put'
  })
}

export function testReOpen(id) {
  return request({
    url: '/v1/test/reopen/' + id,
    method: 'put'
  })
}

export function testClose(id) {
  return request({
    url: '/v1/test/close/' + id,
    method: 'put'
  })
}

export function taskCancel(id) {
  return request({
    url: '/v1/test/cancel/' + id,
    method: 'put'
  })
}

export function testReject(id) {
  return request({
    url: '/v1/test/reject/' + id,
    method: 'put'
  })
}

export function testSubmit(id, codeRepository) {
  return request({
    url: '/v1/test/submit/' + id,
    method: 'put',
    data: {
      codeRepository: codeRepository
    }
  })
}
